using System;
using System.Collections.Generic;
using System.Text;
using SpriteCraft;
using System.Drawing;

namespace SpaceGame
{
  public abstract class Enemy : Player
  {
    protected Point m_CurrentTarget;
    public Enemy(EngineClass engine, Stage stage)
      : base(engine, stage)
    {
    }

    public void GoToPoint(Point p)
    {
      m_CurrentTarget = p;
    }

    public bool IsAtTargetPos()
    {
      return m_Ship.X == m_CurrentTarget.X && m_Ship.Y == m_CurrentTarget.Y;
    }
  }

  public class SmallStandardEnemy : Enemy
  {
    private bool m_toggler;

    public SmallStandardEnemy(EngineClass engine, Stage stage, Point pos) : base(engine, stage)
    {
      m_Ship = new SmallFighterShip(engine, this, Program.EnemyShipCollideGroup, pos);
      pos.Offset(50, 50);
      m_CurrentTarget = pos;
      
      m_toggler = true;
    }

    public SmallStandardEnemy(EngineClass engine, Stage stage)
      : this(engine, stage, new Point(engine.scrWidth / 2, engine.scrHeight - 100))
    { }

    #region IOnUpdate Members

    public override void OnUpdate(ISprite sprite, int tickdelta)
    {
      if (IsAtTargetPos())
      {
        int toggle = m_toggler ? -1 : +1;
        m_toggler = !m_toggler;
        m_CurrentTarget.Offset(toggle * 100, toggle*100);
      }

      m_Ship.DoStuff(m_Stage, tickdelta, m_CurrentTarget);
    }

    public override void OnCollide(ISprite self, ISprite Hit)
    {
      if (!m_isDestroyed)
      {
        m_isDestroyed = true;
        this.Explode(self);

        if (Hit.name.Contains("weapon_"))
        { Hit.Dispose(); }
        self.Dispose();
      }
    }

    #endregion
  }
}
